//
//  ChangePassWordView.m
//  fitnessmanage
//
//  Created by wujian on 2017/12/15.
//  Copyright © 2017年 zongquankeji. All rights reserved.
//

#import "ChangePassWordView.h"

@implementation ChangePassWordView

-(id)initWithFrame:(CGRect)frame{
    
    self = [super initWithFrame:frame];
    
    if (self) {
     
        /**
         滑动视图
         */
        UIScrollView *scrollView = [[UIScrollView alloc] init];
        [self addSubview:scrollView];
        self.scrollView = scrollView;
        
        /**
         白色背景
         */
        UIView *whiteView = [[UIView alloc] init];
        whiteView.backgroundColor = CSWhiteColor;
        [scrollView addSubview:whiteView];
        self.whiteView = whiteView;
        
        /**
         +86
         */
        UILabel *phoneFrontLabel = [[UILabel alloc] init];
        phoneFrontLabel.text = @"中国+86";
        phoneFrontLabel.font = MidBigFont;
        phoneFrontLabel.textColor = CSColorFromRGB(0x666666);
        phoneFrontLabel.textAlignment = NSTextAlignmentLeft;
        [whiteView addSubview:phoneFrontLabel];
        self.phoneFrontLabel = phoneFrontLabel;
        
        UIImageView *downImageView = [[UIImageView alloc] init];
        downImageView.image = [UIImage imageNamed:@"down"];
        [whiteView addSubview:downImageView];
        self.downImageView = downImageView;
        
        NSMutableDictionary *attrs = [NSMutableDictionary dictionary];// 创建属性字典
        attrs[NSFontAttributeName] = MidBigFont; // 设置font
        attrs[NSForegroundColorAttributeName] = PlaceHoldColor; // 设置颜色
        
        /**
         手机TF
         */
        UITextField *phoneTF = [[UITextField alloc] init];
        //        phoneTF.backgroundColor = CSRedColor;
        phoneTF.clearButtonMode=UITextFieldViewModeWhileEditing;
        phoneTF.keyboardType = UIKeyboardTypeNumberPad;
        phoneTF.font = MidBigFont;
        phoneTF.textColor = CSColorFromRGB(0x212121);
        NSAttributedString *phoneAttStr = [[NSAttributedString alloc] initWithString:@"请输入您的手机号" attributes:attrs]; // 初始化富文本占位字符串
        phoneTF.attributedPlaceholder = phoneAttStr;
        [whiteView addSubview:phoneTF];
        self.phoneTF = phoneTF;
        
        UIView *phoneLineView = [[UIView alloc] init];
        phoneLineView.backgroundColor = LineBackGroundColor;
        [whiteView addSubview:phoneLineView];
        self.phoneLineView = phoneLineView;
        
        /**
         验证码TF
         */
        CommonInputView *verCodeView = [[CommonInputView alloc] init];
        verCodeView.titleLabel.text = @"验证码";
        verCodeView.titleTF.placeholder = @"输入验证码";
        verCodeView.titleTF.textAlignment = NSTextAlignmentLeft;
        [whiteView addSubview:verCodeView];
        self.verCodeView = verCodeView;
        
        /**
         发送验证码
         */
        UIButton *sendVercodeBtn = [[UIButton alloc] init];
        [sendVercodeBtn setTitle:@"获取验证码"];
        sendVercodeBtn.titleLabel.font = MidBigFont;
        [sendVercodeBtn setTitleColor:CSColorFromRGB(0x666666)];
        sendVercodeBtn.backgroundColor = CSColorFromRGB(0xf0f0f0);
        [whiteView addSubview:sendVercodeBtn];
        self.sendVercodeBtn = sendVercodeBtn;
        
        /**
         新密码
         */
        CommonInputView *passWordView = [[CommonInputView alloc] init];
        passWordView.titleLabel.text = @"新密码";
        passWordView.titleTF.placeholder = @"输入新密码";
        passWordView.titleTF.textAlignment = NSTextAlignmentLeft;
        passWordView.titleTF.secureTextEntry = YES;
        [whiteView addSubview:passWordView];
        self.passWordView = passWordView;
        
        /**
         确认密码
         */
        CommonInputView *confirmPassView = [[CommonInputView alloc] init];
        confirmPassView.titleLabel.text = @"确认密码";
        confirmPassView.titleTF.placeholder = @"请再次确认密码";
        confirmPassView.titleTF.textAlignment = NSTextAlignmentLeft;
        confirmPassView.titleTF.secureTextEntry = YES;
        [whiteView addSubview:confirmPassView];
        self.confirmPassView = confirmPassView;
        
        /**
         确认按钮
         */
        /**
         确认按钮
         */
        UIButton *sureBtn = [[UIButton alloc] init];
        [sureBtn setTitle:@"确定"];
        [sureBtn setTitleColor:CSColorFromRGB(0x0a0a0a)];
        sureBtn.titleLabel.font = MidBigFont;
        sureBtn.backgroundColor = ButtonBackGroundColor;
        [scrollView addSubview:sureBtn];
        self.sureBtn = sureBtn;

        [self setConstraints];
    }
    
    return self;
}

-(void)setConstraints{
    
    [self.scrollView mas_remakeConstraints:^(MASConstraintMaker *make) {
        
        make.edges.mas_equalTo(self);
    }];
    
    /**
     白色背景
     */
    [self.whiteView mas_remakeConstraints:^(MASConstraintMaker *make) {
        
        make.top.left.width.mas_equalTo(self.scrollView);
    }];
    
    /**
     +86
     */
    [self.phoneFrontLabel mas_remakeConstraints:^(MASConstraintMaker *make) {
        
        make.left.mas_equalTo(self.whiteView).offset(20);
        
        make.centerY.mas_equalTo(self.phoneTF);
        
        make.width.mas_equalTo(77);
    }];
    
    [self.downImageView mas_remakeConstraints:^(MASConstraintMaker *make) {
        
        make.centerY.mas_equalTo(self.phoneFrontLabel);
        
        make.left.mas_equalTo(self.phoneFrontLabel.mas_right).offset(-10);
        
        make.width.height.mas_equalTo(5);
    }];
    
    /**
     手机TF
     */
    [self.phoneTF mas_remakeConstraints:^(MASConstraintMaker *make) {
        
        make.top.mas_equalTo(self.whiteView);
        
        make.left.mas_equalTo(self.downImageView.mas_right).offset(20);
        
        make.right.mas_equalTo(self).offset(-25);
        
        make.height.mas_equalTo(50);
    }];
    
    [self.phoneLineView mas_remakeConstraints:^(MASConstraintMaker *make) {
        
        make.left.mas_equalTo(self.phoneFrontLabel);
        
        make.right.mas_equalTo(self).offset(-25);
        
        make.height.mas_equalTo(1);
        
        make.bottom.mas_equalTo(self.phoneTF);
    }];
    
    /**
     验证码TF
     */
    [self.verCodeView mas_remakeConstraints:^(MASConstraintMaker *make) {
        
        make.top.mas_equalTo(self.phoneLineView.mas_bottom);
        
        make.left.mas_equalTo(self).offset(10);
        
        make.right.mas_equalTo(self.whiteView);
    }];
    
    /**
     发送验证码
     */
    [self.sendVercodeBtn mas_remakeConstraints:^(MASConstraintMaker *make) {
        
        make.right.mas_equalTo(self.whiteView).offset(-15);
        
        make.width.mas_equalTo(120);
        
        make.height.mas_equalTo(40);
        
        make.centerY.mas_equalTo(self.verCodeView);
    }];
    
    /**
     新密码
     */
    [self.passWordView mas_remakeConstraints:^(MASConstraintMaker *make) {
       
        make.top.mas_equalTo(self.verCodeView.mas_bottom);
        
        make.left.width.mas_equalTo(self.verCodeView);
        
    }];
    
    /**
     确认密码
     */
    [self.confirmPassView mas_remakeConstraints:^(MASConstraintMaker *make) {

        make.top.mas_equalTo(self.passWordView.mas_bottom);

        make.left.width.mas_equalTo(self.verCodeView);
        
        make.bottom.mas_equalTo(self.whiteView);
    }];
    
    [self.sureBtn mas_remakeConstraints:^(MASConstraintMaker *make) {

        make.top.mas_equalTo(self.whiteView.mas_bottom).offset(30);

        make.left.mas_equalTo(self.scrollView).offset(20);

        make.right.mas_equalTo(self).offset(-20);

        make.height.mas_equalTo(50);
    }];
}

@end
